package com.bw.shop2208a.detail

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bw.shop2208a.entity.*
import com.bw.shop2208a.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class DetailViewModel : BaseViewModel() {
    var successDetail = MutableLiveData<DetailEntity>()
    var failDetail = MutableLiveData<String>()

    fun getDetail(goods_id:Int){
        viewModelScope.launch {
            try {
                successDetail.value = apiservice.getDetail(goods_id)
            } catch (e: Exception) {
                failDetail.value = e.message
            }
        }
    }

    var successAddCar = MutableLiveData<AddCarResult>()
    var failAddCar = MutableLiveData<String>()

    fun addCar(addcarParam: AddcarParam){
        viewModelScope.launch {
            try {
                successAddCar.value = apiservice.addCar(addcarParam)
            } catch (e: Exception) {
                failAddCar.value = e.message
            }
        }
    }
}